#include "stdio.h"
#include "string.h"
#define N 1100

char tu[N][N],dian='.';
int maxrope;

int dsf(int x,int y)
{
	int len[4],i,j,a,b;
	for (i=0;i<4;i++) len[i]=0;
	tu[x][y]='#';
	a=x-1;b=y;
	if (tu[a][b]==dian)
	{
		len[0]=dsf(a,b)+1;
	}
	a=x+1;b=y;
	if (tu[a][b]==dian)
	{
		len[1]=dsf(a,b)+1;
	}
	a=x;b=y-1;
	if (tu[a][b]==dian)
	{
		len[2]=dsf(a,b)+1;
	}
	a=x;b=y+1;
	if (tu[a][b]==dian)
	{
		len[3]=dsf(a,b)+1;
	}
	for (i=0;i<3;i++)
		for (j=i+1;j<=3;j++)
			if ((len[i]+len[j]) > maxrope)
				maxrope=len[i]+len[j];
	b=len[0];
	for (i=1;i<=3;i++)
		if (b<len[i])
			b=len[i];
	return b;
}

void main()
{
	int i,j,l,ncase,x,y,b;
	int c,r;
	scanf("%d",&ncase);
	for (l=0;l<ncase;l++)
	{
		maxrope=0;
		scanf("%d%d",&c,&r);
		for (i=0;i<r;i++)
		{
			scanf("%s",tu[i]);
		}
		for (i=1;i<r-1;i++)
		{
			b=0;
			for (j=1;j<c-1;j++)
				if (tu[i][j]==dian) 
				{
					x=i;y=j;
					b=1;
					break;
				}
			if (b) break;
		}
		dsf(x,y);			
		printf("Maximum rope length is %d.\n",maxrope);
	}
	
}
/*
*	name:Labyrinth  
		Central Europe 1999
	type:graph
	submit time : 1 pass
	finish time: 2004/9/16
	method :
		深度优先搜索，因为是无环的，所以可以看成是对树的搜索。每搜到一个节点把此节点删去。
		用一个数组len[4]记下当前节点的四个方向最长的长度。因为有可能起点并不在树根，所以每搜一个节点，
		把这个节点四个方向中的长度选两个最大的加起来，和maxrope比较，如果比maxrope大就取代
		maxrope的值。
	note: before i passed it ,my acm-team had just discussed the problem.
		so,i know the arithmetic.
 */